package com.ztjy.statis.controller;

import com.github.pagehelper.PageInfo;
import com.ztjy.bean.City;
import com.ztjy.bean.CustomStatis;
import com.ztjy.bean.RkStatis;
import com.ztjy.bean.Users;
import com.ztjy.statis.biz.CustomStatisBiz;
import com.ztjy.sys.biz.AreaBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/statis/custom")
public class CustomStatisController {
    @Autowired
    private CustomStatisBiz custombiz;
    @Autowired
    private AreaBiz abiz;

    @RequestMapping("/allcustomstatis")
    public String findAllCustomStatis(Model model, CustomStatis customStatis, @RequestParam(defaultValue = "1",value = "pageno")Integer pageNo, HttpSession session){
        Integer pageSize=6;
        Users user=(Users) session.getAttribute("currUser");
        Integer jobId = user.getJobId();
        if (jobId==2||jobId==1){
            PageInfo<CustomStatis> allCustomStatis = custombiz.findAllCustomStatis(customStatis, pageNo, pageSize);
            model.addAttribute("customstatisinfo",allCustomStatis);
            if(customStatis!=null){
                Integer cityId = customStatis.getCid();
                City city = abiz.findCityById(cityId);
                customStatis.setCity(city);
            }
            model.addAttribute("customStatis",customStatis);
            return "forward:/statis/sales/salesStatis.html";
        }else{
            return "";
        }
    }

    @RequestMapping("/customview")
    public String findRkView(Model model,Integer id,@RequestParam(defaultValue = "1",value = "pageno")Integer pageNo){
        Integer pageSize=6;
        PageInfo<CustomStatis> customstatisById = custombiz.findCustomStatisById(id, pageNo, pageSize);
        model.addAttribute("allcustombyid",customstatisById);
        model.addAttribute("id",id);
        return "forward:/statis/sales/salesView.html";
    }

    @RequestMapping("/bingzhuang")
    @ResponseBody
    public List<CustomStatis> bingZhuang(){
        List<CustomStatis> customStatis = custombiz.findbingZhuangtu();
        return customStatis;
    }
}
